var util = require('../../../utils/util.js');
Page({
  data: {
    activitystate: [
      { name: '上线', value: '0', checked: 'true' },
      { name: '下线', value: '1' },
      { name: "结束", value: '2' }
    ],
    state: 0,
    sendtype: ['每人一次', '每人每天一次', '不限次'],
    sendtypes: [{ name: '每人一次', value: '0', checked: 'true' },
    { name: '每人每天一次', value: '1' },
    { name: '不限次', value: '2' },],
    reds: [
      { id: 2, title: "全部商品9.5折", summary: "庆祝双十一，促销大打折", redtype: 0, startTime: "2019-11-10 00:00:00", endTime: "2019-11-12 00:00:00", discount: 9.5 },
      { id: 1, title: "全部商品满减", summary: "满30减5元，满60减15元", redtype: 1, startTime: "2019-11-10 00:00:00", endTime: "2019-11-12 00:00:00", full: '30/50/100', reduce: '3/6/12' },
    ]

  },
  onLoad: function () {
    this.getRedAcList();
  },
  addRedActivity: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: 'redactivityadd' + "?id=" + id,
    })
  },
  getRedAcList: function () {
    var that = this;
    var url = util.url.shop_redpacket_listredact//"/red/listredact";
    util.fetchGet(
      url,
      function (ret) {
        var list = ret.data;
        for (var i = 0; i < list.length; i++) {
          if (list[i].redtype == 1) {
            var reduction = list[i].reduction;
            var full = ""; var reduce = "";
            for (var j = 0; j < reduction.length; j++) {
              
              full += reduction[j].full
              reduce += reduction[j].reduce
              if (j != reduction.length-1) {
                full += "/";
                reduce += "/";
              }
            }
            list[i].full = full;
            list[i].reduce = reduce;
            
          }
          list[i].sendtype = that.getsendtype(list[i].sendtype);
        }
        that.setData({
          reds: list
        })
      }
    )
  },
  getsendtype:function(sendtype){
    var sendtypes = this.data.sendtypes;
    for (var i = 0; i < sendtypes.length;i++){
      if (sendtype == sendtypes[i].value){
        return sendtypes[i].name
      }
    }
  },
  gotoedit:function(e){
    var id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: 'redactivityadd?id='+id,
    })
  }
})